home *** CD-ROM | disk | FTP | other *** search
/ QuickTime 2.0 Developer Kit / QuickTime 2.0 Developer Kit.iso / mac / MAC / Programming Stuff / Documentation / develop / develop Issue 12 / develop 12 code / Components / MathComponentCommon.c < prev    next >
Encoding:
Text File  |  1992-10-16  |  3.7 KB  |  163 lines  |  [TEXT/KAHL]

  1. /*
  2.     File:        MathComponentCommon.c
  3.  
  4.     Contains:    Math component routines.
  5.  
  6.     Written by:    Gary Woodcock
  7.  
  8.     Copyright:    © 1992 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12. */
  13.  
  14. //-----------------------------------------------------------------------
  15. // Includes
  16.  
  17. #include "MathComponent.h"
  18. #include "MathComponentCommon.h"
  19. #include "MathComponentPrivate.h"
  20. #include <OSUtils.h>
  21.  
  22. //-----------------------------------------------------------------------
  23.  
  24. pascal    ComponentResult    _MathOpen    (Handle                storage,
  25.                                      ComponentInstance    self)
  26. {
  27.     #pragma    unused (storage)
  28.     
  29.     ComponentResult        result = noErr;
  30.     PrivateGlobals**    globals;
  31.     
  32.     // Can we open another instance?
  33.     if (CountComponentInstances ((Component) self) <= kMaxMathInstances)
  34.     {
  35.         // Did we get our storage?
  36.         globals = (PrivateGlobals**) NewHandleClear (sizeof (PrivateGlobals));
  37.         if (globals != nil)
  38.         {
  39.             // Keep a reference to self
  40.             (*globals)->self = (Component) self;
  41.             
  42.             // Init private fields
  43.             (*globals)->capturingComponentInstance = 0L;
  44.             (*globals)->delegateComponent = 0L;
  45.             (*globals)->delegateComponentInstance = 0L;
  46.             
  47.             // Set storage ref
  48.             SetComponentInstanceStorage (self, (Handle) globals);
  49.         }
  50.         else    // NewHandleClear failed
  51.         {
  52.             result = MemError();
  53.         }
  54.     }
  55.     else    // No more instances can be opened
  56.     {
  57.         result = kGenericError;
  58.     }
  59.     return (result);
  60. }
  61.  
  62. //-----------------------------------------------------------------------
  63.  
  64. pascal    ComponentResult    _MathClose    (Handle                storage,
  65.                                      ComponentInstance    self)
  66. {
  67.     ComponentResult        result = noErr;
  68.     PrivateGlobals**    globals = (PrivateGlobals**) storage;
  69.     
  70.     // Do we have any clean up to do?
  71.     if (globals != nil)
  72.     {
  73.         // Dispose globals
  74.         DisposHandle ((Handle) globals);
  75.     }
  76.     return (result);
  77. }
  78.  
  79. //-----------------------------------------------------------------------
  80.  
  81. pascal    ComponentResult    _MathCanDo    (short    selector)
  82. {
  83.     // Case on the request code
  84.     switch (selector)
  85.     {
  86.         // Component Manager request codes
  87.         case kComponentOpenSelect:
  88.         case kComponentCloseSelect:
  89.         case kComponentCanDoSelect:
  90.         case kComponentVersionSelect:
  91.         case kComponentTargetSelect:
  92.         
  93.         // Math component request codes
  94.         case kDoDivideSelect:
  95.         case kDoMultiplySelect:
  96.         {
  97.             return (true);
  98.         }
  99.         case kComponentRegisterSelect:    // Register request not supported
  100.         default:                        // Not a request code we recognize
  101.         {
  102.             return (false);
  103.         }
  104.     }
  105. }
  106.  
  107. //-----------------------------------------------------------------------
  108.  
  109. pascal    ComponentResult    _MathVersion    (void)
  110. {
  111.     // Return the version info
  112.     return (mathInterfaceRevision);
  113. }
  114.  
  115. //-----------------------------------------------------------------------
  116.  
  117. pascal    ComponentResult    _MathTarget    (Handle                storage,
  118.                                      ComponentInstance    capturingComponent)
  119. {
  120.     ComponentResult        result = noErr;
  121.     PrivateGlobals**    globals = (PrivateGlobals**) storage;
  122.     
  123.     // Set reference to capturing component
  124.     (*globals)->capturingComponentInstance = capturingComponent;
  125.     
  126.     return (result);
  127. }
  128.  
  129. //-----------------------------------------------------------------------
  130.  
  131. pascal    ComponentResult    _MathDoDivide    (short    numerator,
  132.                                          short    denominator,
  133.                                          short    *quotient)
  134. {
  135.     ComponentResult    result = noErr;
  136.     
  137.     if (denominator != 0)
  138.     {
  139.         *quotient = numerator/denominator;
  140.     }
  141.     else    // Divide by zero not allowed
  142.     {
  143.         *quotient = 0;
  144.         result = kGenericError;    
  145.     }
  146.     return (result);
  147. }
  148.  
  149. //-----------------------------------------------------------------------
  150.  
  151. pascal    ComponentResult    _MathDoMultiply    (short    firstNum,
  152.                                          short    secondNum,
  153.                                          short    *multiplicationResult)
  154. {
  155.     ComponentResult    result = noErr;
  156.     
  157.     *multiplicationResult = firstNum * secondNum;
  158.     
  159.     return (result);
  160. }
  161.     
  162. //-----------------------------------------------------------------------
  163.